package com.powernode.ssm.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.powernode.ssm.pojo.po.UserLoginAttempt;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.time.LocalDateTime;

@Mapper
public interface UserLoginAttemptMapper extends BaseMapper<UserLoginAttempt> {

    /**
     * 根据 IP 查询登录尝试记录
     */
    UserLoginAttempt findByIp(@Param("ip") String ip);

    /**
     * 更新或插入 IP 登录尝试记录（UPSERT）
     */
    int upsertAttempt(@Param("ip") String ip,
                      @Param("shortAttempts") Integer shortAttempts,
                      @Param("longAttempts") Integer longAttempts,
                      @Param("isBlocked") Integer isBlocked,
                      @Param("shortExpireTime") LocalDateTime shortExpireTime,
                      @Param("longExpireTime") LocalDateTime longExpireTime,
                      @Param("blockExpireTime") LocalDateTime blockExpireTime);

    /**
     * 自定义删除方法：删除 createdAt 早于指定时间的记录
     */
    int deleteByCreatedAtBefore();
}